from plotly.graph_objs import Bar, Layout
from plotly import offline
from die import Die

# 6面的骰子执行100次
die = Die(6)
result = []
for roll_number in range(1000):
    result.append(die.roll())
print(result)

# 分析每个点数出现次数
frequencies = []
for value in range(1, die.num_sides + 1):
    frequency = result.count(value)
    frequencies.append(frequency)
print(frequencies)

# 绘制直方图
x_values = list(range(1, die.num_sides + 1))
data = [Bar(x=x_values, y=frequencies)]
x_axis_config = {'title': '结果'}
y_axis_confi = {'title': '结果出现次数'}
my_layout = Layout(title="投掷一个D6 1000次结果", xaxis=x_axis_config, yaxis=y_axis_confi)

offline.plot({'data': data, 'layout': my_layout}, filename='d6.html')
